<?php
/**
 * Index controller.
 *
 * @category PhpCilux
 * @package  PhpCilux
 */

/**
 * Index controller.
 *
 * @package PhpCilux
 */
class IndexController extends Zend_Controller_Action
{

    /**
     * Action with overview over all projects.
     *
     * @return void
     */
    public function indexAction()
    {
        $mapper = Model_ProjectMapper::getInstance();
        $this->view->projects = $mapper->findAll();
    }

    /**
     * Action for project handling.
     *
     * @return void
     */
    public function projectAction()
    {
        $projectKey = $this->getRequest()->getParam('project');

        $mapper  = Model_ProjectMapper::getInstance();
        $project = $mapper->find($projectKey);

        if ($this->getRequest()->has('build')) {
            $buildKey = $this->getRequest()->getParam('build');
            $build    = $project->getBuild($buildKey);
        }

        if (!$build instanceof Model_Build) {
            $build = $project->getLastBuild();
        }

        $this->view->project = $project;
        $this->view->build   = $build;
    }

}

